<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>请假记录列表</h1>
    <a href="/leaverecords/save" th:href="@{/leaverecords/save}">添加请假记录 </a>
    <table border="1">
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>请假时间</th>
            <th>请假原因</th>
            <th>操作</th>
        </tr>
        <tr th:each="abc:${pageInfo.records}">
            <td th:text="${abc.id}"></td>
            <td th:text="${abc.name}"></td>
            <td th:text="${#temporals.format(abc.leaveTime,'yyyy-MM-dd')}"></td>
            <td th:text="${abc.reason}"></td>
            <td><a href="javascript:void(0)" th:onclick="|del(${abc.id})|">删除</a></td>
        </tr>
    </table>
    <div>
        <a th:if="${pageInfo.current>1}" href="/leaverecords/page" th:href="@{/leaverecords/page(pageNo=1)}">首页</a>
        <a th:if="${pageInfo.current>1}" href="/leaverecords/page" th:href="@{/leaverecords/page(pageNo=${pageInfo.current-1})}">上一页</a>
        <a th:if="${pageInfo.current<pageInfo.pages}" href="/leaverecords/page" th:href="@{/leaverecords/page(pageNo=${pageInfo.current+1})}">下一页</a>
        <a th:if="${pageInfo.current<pageInfo.pages}" href="/leaverecords/page" th:href="@{/leaverecords/page(pageNo=${pageInfo.pages})}">尾页</a>
        <span th:text="|第${pageInfo.current}页/共${pageInfo.pages}页|"></span>
    </div>
</body>
</html>
<script src="../static/jquery.js" th:src="@{/jquery.js}"></script>
<script>
    /** 删除信息 */
    function del(id){
        // 弹出确认框
        if(confirm("确认要删除吗？")){
            $.ajax({
                // 使用Restful风格
                url: "/leaverecords/del/" + id,
                type: "DELETE",
                dataType: "json",
                success: function(data){
                    if(data.code == 200){
                        // 正常状态
                        alert("数据删除成功！");
                        //刷新页面
                        location.reload();
                    }else{
                        if(data.msg){
                            // 如果后端传递了错误信息，则显示后端提供的
                            alert(data.msg);
                        }else{
                            alert("数据删除失败，请重试！");
                        }

                    }
                }
            })
        }
    }

</script>